import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import set from '@dfeidao/atom-web/local/set';
// import s_get from '@dfeidao/atom-web/storage/get';
import { spaceid } from './config';

import nodejs from '@dfeidao/atom-web/msg/nodejs';
// import whoami from '@dfeidao/atom-web/msg/whoami';
import render from '@dfeidao/atom-web/render/render';
import p001 from './p001';
import p002 from './p002';
import p005 from './p005';

export default async function a002(fd: IFeidaoAiBrowserComponent, args: { moid: string, currentTarget: HTMLElement, compen: string, event: string }) {
	//  调用事件
	fd.data.node.classList.remove('display-n');
	// const user = await whoami();
	// const prid = await s_get('productid');
	// const user = await whoami(get_user_info);
	// console.log(user)
	set(fd, 'productid', spaceid);
	const data = args;

	set(fd, 'compen', data.compen);
	set(fd, 'event', data.event);

	const page_no = 1;
	const page_size = 10;
	const modid = data.moid;

	const query = {
		filter: {
			modelid: {
				$regex: '.*' + modid + '.*',
				$options: "i"
			},
			productid: spaceid
		},
		page_no,
		page_size
	};
	if (!modid) {
		delete query.filter.modelid;
	}

	// const res = await nodejs<{ count: number; dataArray: object[]; page_size: number; page_no: number }>(url, './permissions/role_type_find2', query, false, false);
	const res = await nodejs<{ count: number; dataArray: object[]; page_size: number; page_no: number }>('role-type/zj-000003/s001', query);
	if (res.dataArray.length === 0) {
		render(fd, '', p001, 'p001', 'inner');
		render(fd, '', p002, 'p002', 'inner');

	} else {
		render(fd, res.dataArray, p001, 'p001', 'inner');
		res.page_no = page_no;
		res.page_size = page_size;
		render(fd, res, p005, 'p005', 'inner');
	}
	fd.data.node.querySelector<HTMLInputElement>('#name').value = modid ? modid : '';
}
